import 'package:shared_preferences/shared_preferences.dart';

import '../constants/index.dart';

class TokenManager {
  // 初始化首选项实例
  Future<SharedPreferences> _getInstance() {
    return SharedPreferences.getInstance();
  }

  // 存储token
  setToken(String token) async {
    // 获取首选项实例
    final instance = await _getInstance();
    // 基于实例 存储
    instance.setString(GlobalVariable.TOKEN_KEY, token);
  }

  // 获取token
  getToken() async {
    // 获取首选项实例
    final instance = await _getInstance();
    return instance.getString(GlobalVariable.TOKEN_KEY);
  }

  // 删除token
  deleteToken() async {
    // 获取首选项实例
    final instance = await _getInstance();
    instance.remove(GlobalVariable.TOKEN_KEY);
  }
}
